package com.example.service.impl;

import com.example.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailMessage;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@Service
public class SendMailServiceImpl2 implements SendMailService {
    @Autowired
    private JavaMailSender javaManager;

    private String senderHost = "2194588563@qq.com";

    private String toMali = "3403911688@qq.com";

    private String title = "测试";

    private String context =  "https://tse2-mm.cn.bing.net/th/id/OIP-C.YTuOZzeVIwC_i_pGIry3cQHaMK?w=182&h=299&c=7&r=0&o=5&dpr=1.25&pid=1.7" ;



    @Override
    public void sendMail() {
        try {
            MimeMessage mimeMessage = javaManager.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
            File file1 = new File("F:\\java编程合集\\SpringBoot\\springboot_22_mail\\src\\main\\resources\\application.yml");
            File file = new File("F:\\java编程合集\\SpringBoot\\springboot_22_mail\\src\\main\\java\\com\\example\\service\\impl\\SendMailServiceImpl2.java");
            helper.setFrom(senderHost);
            helper.addAttachment("send.java",file);
            helper.addAttachment("yml.yml",file1);
            helper.setTo(toMali);
            helper.setSubject(title);
            helper.setText(context,true);
            javaManager.send(mimeMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
